<template>
	<view class="content">
		<view class="listBox">
			<view class="item" @click="seeAgreement('register')">
				<view class="tit">注册协议</view>
				<uni-icons type="right" size="24" color="#999999"></uni-icons>
			</view>
			<view class="item" @click="seeAgreement('privacy')">
				<view class="tit">隐私政策</view>
				<uni-icons type="right" size="24" color="#999999"></uni-icons>
			</view>
			<view class="item" @click="seeAgreement('copyright')">
				<view class="tit">版权声明</view>
				<uni-icons type="right" size="24" color="#999999"></uni-icons>
			</view>
			<view class="item" @click="seeAgreement('exemption')">
				<view class="tit">免责声明</view>
				<uni-icons type="right" size="24" color="#999999"></uni-icons>
			</view>
		</view>
		<button class="warn" type="warn" @tap="logoff()" v-if="is_login">注销账号</button>
	</view>
</template>

<script>
	import common from '@/static/js/common';

	export default {
		data() {
			return {
				type: '',
				is_login: false
			}
		},
		onShow() {
			if (uni.getStorageSync('token') && uni.getStorageSync('token') != '') {
				this.is_login = true
			}
		},
		methods: {
			seeAgreement(type) {
				uni.navigateTo({url:'/pages/other/agreement?type='+type})
			},
			logoff() {
				let that = this;
				uni.showModal({
					title: '温馨提示',
					content: '账号注销后所有数据将清空且不可恢复',
					confirmText: '注销账号',
					success: function (res) {
						if (res.confirm) {
							common.api({
								method: 'POST',
								url: '/mobile/user/cancellation',
								success:(res) => {
									if (res.code != 0) {
										uni.showToast({ title: res.msg, icon: 'none' });
										return false;
									}
									uni.reLaunch({url:'/pages/login/index'})
								}
							});
						}
					}
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	.listBox {
		background-color: #fff;
		margin-top: 30rpx;
		.item {
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 3vw;
			&+.item {
				border-top: 2rpx solid #eee;
			}
			.tit {
				display: flex;
				align-items: center;
				.uni-icons {
					margin-right: 10rpx;
				}
			}
			.arrow {
				height: 30rpx;
			}
		}
	}
	.warn {
		width: 80vw;
		margin: 50rpx auto 0;
	}
</style>
